package com.kgcx.system.service;

import com.github.pagehelper.PageHelper;
import com.kgcx.common.bean.RequestData;
import com.kgcx.common.constant.Cons;
import com.kgcx.dbutils.utils.PageUtils;
import com.kgcx.system.domain.Suggestion;
import com.kgcx.system.mapper.SuggestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 吴刚林
 * @date 2017/11/20
 */
@Service
public class SuggestionService {

    @Autowired
    private SuggestionMapper suggestionMapper;


    public Suggestion getSuggestion(Long kid) {
        return suggestionMapper.selectByPrimaryKey(kid);

    }

    public List<Suggestion> getSuggestionList(RequestData rd) {
        PageUtils.page(rd);
        PageHelper.orderBy(rd.getOrderBy());
        return suggestionMapper.selectAllActive();

    }

    @Transactional(rollbackFor = Exception.class)
    public void addSuggestion(Suggestion suggestion) {
        suggestionMapper.insertSelective(suggestion);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateSuggestion(Suggestion suggestion) {
        suggestionMapper.updateByPrimaryKeySelective(suggestion);

    }

    @Transactional(rollbackFor = Exception.class)
    public void removeSuggestion(Long kid) {
        Suggestion suggestion = new Suggestion();
        suggestion.setKid(kid);
        suggestion.setStatus(Cons.COMMON_STATUS_DELETE);
        suggestionMapper.updateByPrimaryKeySelective(suggestion);

    }
}
